home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / dialgmgr.sit / Dialogs ƒ / UserItem.p < prev   
Encoding:
Text File  |  1989-11-29  |  3.5 KB  |  154 lines  |  [TEXT/PJMM]

  1. unit TUserItem;
  2.  
  3. {        ⌐1986-1989            Bill Stackhouse                                    }
  4. {                                Stackhouse Software                                }
  5. {                                Natick, MA 01760                                    }
  6.  
  7. interface
  8.  
  9. {$IFC UNDEFINED UseUserItem}
  10. {$SETC UseUserItem = FALSE}
  11. {$ENDC}
  12. {$IFC UseUserItem}
  13.  
  14.     uses
  15.         TObject;
  16.  
  17.     const
  18.         maxUserItems = 10;
  19.  
  20.     type
  21.         TUserItem = object(TObject)
  22.                 numUserItems: 0..maxUserItems;                {number of there user items}
  23.                 UserItem: array[1..maxUserItems] of record
  24.                         num: Integer;                    {number of item with this box}
  25.                         box: Rect;                        {bounds of user item}
  26.                         event: ProcPtr;                            {}
  27.                         select: ProcPtr;                            {}
  28.                         draw: ProcPtr;                {}
  29.                     end;
  30.                 procedure TUserItem.Init;
  31.                 procedure TUserItem.Add (pBtn: Integer;    {user item number}
  32.                                             pDraw, pEvent, pSelect: ProcPtr;    {}
  33.                                             pBox: Rect);                            {}
  34.                 procedure TUserItem.Revise (curDialog: DialogPtr);
  35.                 procedure TUserItem.Mouse (curDialog: DialogPtr;
  36.                                             theEvent: EventRecord);
  37.                 function TUserItem.Error: Integer;
  38.             end;
  39.  
  40. {$ENDC}
  41.  
  42. implementation
  43.  
  44. {$IFC UseUserItem}
  45.  
  46.     const
  47.         Off = 0;
  48.         On = 1;
  49.  
  50.         btnCtrlItem = 4;
  51.         chkCtrlItem = 5;
  52.         radCtrlItem = 6;
  53.         editCtrlItem = 16;
  54.  
  55.         DialogGroupIgnored = -10;    {too many groups, key, menus, or user items were added}
  56.  
  57.     type
  58.         TSearch = (searching, found, endList);
  59.  
  60.     var
  61.         globalError: Integer;
  62.  
  63.     function UserEvent (theDialog: DialogPtr;
  64.                                     var theEvent: EventRecord;
  65.                                     var item: Integer;
  66.                                     proc: ProcPtr): Boolean;
  67.     inline
  68.         $205f,     {movea.l  (a7)+,a0        ; (a0) is a ptr to string, 4(a0) is mode}
  69.         $4e90;
  70.  
  71.     procedure UserSelect (theDialog: DialogPtr;
  72.                                     item: Integer;
  73.                                     proc: ProcPtr);
  74.     inline
  75.         $205f,     {movea.l  (a7)+,a0        ; (a0) is a ptr to string, 4(a0) is mode}
  76.         $4e90;
  77.  
  78.     procedure TUserItem.Init;
  79.     begin
  80.         globalError := noErr;
  81.         SELF.numUserItems := 0;
  82.     end;        {TUserItem.Init}
  83.  
  84.     procedure TUserItem.Add (pBtn: Integer;    {user item number}
  85.                                     pDraw, pEvent, pSelect: ProcPtr;    {}
  86.                                     pBox: Rect);                            {}
  87.     begin
  88.         globalError := noErr;
  89.         with SELF do
  90.             if numUserItems < maxUserItems then
  91.                 begin
  92.                     numUserItems := numUserItems + 1;
  93.                     with UserItem[numUserItems] do
  94.                         begin
  95.                             num := pBtn;
  96.                             box := pBox;
  97.                             draw := pDraw;
  98.                             event := pEvent;
  99.                             select := pSelect;
  100.                         end;
  101.                 end
  102.             else
  103.                 globalError := DialogGroupIgnored;
  104.     end;        {TUserItem.Add}
  105.  
  106.     procedure TUserItem.Revise (curDialog: DialogPtr);
  107.         var
  108.             i, j: Integer;
  109.             theType: Integer;
  110.             theHandle: Handle;
  111.             theBox: Rect;
  112.     begin
  113.         globalError := noErr;
  114.         for i := 1 to SELF.numUserItems do
  115.             with SELF.UserItem[i] do
  116.                 begin
  117.                     GetDItem(curDialog, num, theType, theHandle, box);
  118.                     SetDItem(curDialog, num, theType, Handle(draw), box);
  119.                 end;
  120.     end;        {TUserItem.Revise}
  121.  
  122.     procedure TUserItem.Mouse (curDialog: DialogPtr;
  123.                                     theEvent: EventRecord);
  124.         var
  125.             i: Integer;
  126.     begin
  127.         globalError := noErr;
  128.         GlobalToLocal(theEvent.where);                            {because PtInRect wants it that way}
  129.         with SELF do
  130.             begin
  131.                 if numUserItems > 0 then
  132.                     for i := 1 to numUserItems do
  133.                         with UserItem[i] do
  134.                             if PtInRect(theEvent.where, box) then
  135.                                 begin
  136.                                     if event <> nil then
  137.                                         begin
  138.                                             if UserEvent(curDialog, theEvent, num, event) then
  139.                                                 UserSelect(curDialog, num, select);
  140.                                         end;
  141.                                     Leave;
  142.                                 end;
  143.             end;
  144.         LocalToGlobal(theEvent.where);                {because Dlog Mgr wants it that way}
  145.     end;        {TUserItem.Mouse}
  146.  
  147.     function TUserItem.Error: Integer;
  148.     begin
  149.         Error := globalError;
  150.     end;        {TUserItem.Error}
  151.  
  152. {$ENDC}
  153.  
  154. end.